package cn.samler.diandi.api.model.io.request.user;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

@Data
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type", visible = true)
@JsonSubTypes({
        @JsonSubTypes.Type(value = Login.Origin.class, name = Login.Type.ORIGINAL),
        @JsonSubTypes.Type(value = Login.Telephone.class, name = Login.Type.TELEPHONE),
        @JsonSubTypes.Type(value = Login.WechatMiniProgram.class, name = Login.Type.WECHAT_MINI_PROGRAM)
})
public class Login {
    public static class Type {
        // 账号密码登录
        protected static final String ORIGINAL = "original";
        // 手机号登录 可能用不上
        protected static final String TELEPHONE = "telephone";
        // 微信小程序登录
        protected static final String WECHAT_MINI_PROGRAM = "wechat_mini_program";
    }


    @Valid
    @EqualsAndHashCode(callSuper = true)
    @Data
    public static class Origin extends Login {
        @NotBlank(message = "用户名不能为空")
        private String username;

        @NotEmpty(message = "密码不能为空")
        private String password;

        @Valid
        @NotNull(message = "captcha must be not null")
        private TencentCaptchaForm captcha;
    }

    @Valid
    @EqualsAndHashCode(callSuper = true)
    @Data
    public static class Telephone extends Login {
        @NotBlank(message = "手机号不能为空")
        private String telephone;

        @NotBlank(message = "验证码不能为空")
        private String smsCode;
    }

    @Valid
    @EqualsAndHashCode(callSuper = true)
    @Data
    public static class WechatMiniProgram extends Login {
        @NotBlank(message = "code must be not null")
        private String code;
    }
}
